package com.example.demo.Mapper;

import com.example.demo.entity.ClientAsset;
import com.example.demo.entity.ProductInfo;
import com.huawei.shade.org.joda.time.DateTime;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface ProductMapper {
    @Select("select * from product")
    List<ProductInfo> getProducts();

    @Insert("insert into product(product_id,product_name,discription,floor,sale_location,last_time) values(#{product_id},#{product_name},#{discription},#{floor},#{sale_location},#{last_time})")
    public int addProductInfo(int product_id,String product_name,String discription,double floor,String sale_location,int last_time);

    @Insert("insert into buy(product_id,client_id,amount) values(#{product_id},#{client_id},#{amount})")
    public int buyProductInfo(int product_id, int client_id, int amount);

    @Update("update buy set amount=amount-#{sell_amount} where (client_id=#{client_id} and product_id=#{product_id})")
    public int sellProductInfo(int product_id,int client_id, int sell_amount);

    @Update("update product " +
            "set product_name=#{product_name},discription=#{discription},floor=#{floor},sale_location=#{sale_location},last_time=#{last_time} " +
            "where product_id=#{product_id}")
    public int updateProductInfo(int product_id,String product_name,String discription,double floor,String sale_location,int last_time);
}
